package control;

import java.awt.CardLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import data.ChallengeData;
import data.HighscoreEntry.DIFFICULTY;
import data.Options;

public class OptionsMenuManager implements ActionListener, Manager{

	private Control control;
	private Options opt;
	private final int roundmax = 10;

	public OptionsMenuManager(Control c){
		control = c;
		opt = control.getOptions();
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if (e.getActionCommand().equals("difficulty")){
			if(opt.getDifficulty() == DIFFICULTY.HARD){
				opt.setDifficulty(DIFFICULTY.EASY);
			}else{
				opt.setDifficulty(DIFFICULTY.values()[opt.getDifficulty().ordinal() + 1]);
			}
		}else if (e.getActionCommand().equals("ElementCount")){
			ChallengeData tmp = opt.getChallenges()[Options.challengesEnum.ElementCount.ordinal()];
			if(tmp.getRounds() == roundmax){
				tmp.setRounds(0);
			}else{
				tmp.setRounds(tmp.getRounds()+1);
			}

		}else if (e.getActionCommand().equals("FallingBox")){

			ChallengeData tmp = opt.getChallenges()[Options.challengesEnum.FallingBox.ordinal()];
			if(tmp.getRounds() == roundmax){
				tmp.setRounds(0);
			}else{
				tmp.setRounds(tmp.getRounds()+1);
			}

		}else if (e.getActionCommand().equals("FindTheCharacter")){
			ChallengeData tmp = opt.getChallenges()[Options.challengesEnum.FindTheCharacter.ordinal()];
			if(tmp.getRounds() == roundmax){
				tmp.setRounds(0);
			}else{
				tmp.setRounds(tmp.getRounds()+1);
			}
		}else if (e.getActionCommand().equals("FindTheOriginal")){
			ChallengeData tmp = opt.getChallenges()[Options.challengesEnum.FindTheOriginal.ordinal()];
			if(tmp.getRounds() == roundmax){
				tmp.setRounds(0);
			}else{
				tmp.setRounds(tmp.getRounds()+1);
			}
		}else if (e.getActionCommand().equals("Back")){
			CardLayout cl = (CardLayout)(control.gui.getMenus().getLayout());
			IOManager.saveOptions(opt);
			cl.show(control.gui.getMenus(), "MainMenu");
			return;
		}
		control.gui.optionsmenu.update();
	}
}